package core

import (
	"fyne.io/fyne/v2"
)

// 小组件注册, 用于统一管理全局组件,便于跨文件调用
var ComponentMap = make(map[string]fyne.CanvasObject)

// 注册组件
func RegisterComponent(name string, component fyne.CanvasObject) fyne.CanvasObject {
	//判断是否已经注册
	if _, ok := ComponentMap[name]; ok {
		panic(name + "已经注册过了")
	}
	ComponentMap[name] = component
	return component
}

// 获取组件
func GetComponent(name string) fyne.CanvasObject {
	if component, ok := ComponentMap[name]; ok {
		return component
	}
	return nil
}
